﻿using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Theming;
using System.Collections.Generic;

namespace SBPweb.PROvibe.Presentation.Client.Controls.Themes
{

    public class ThemeManager
    {

        #region Private fields

        private Application app;
        private Assembly asm;
        private List<string> themeNames;

        #endregion

        #region Constructor logic

        public ThemeManager(Application app)
            : this(app, Assembly.GetCallingAssembly())
        {
        }

        public ThemeManager(Application app, Assembly asm)
        {
            this.app = app;
            this.asm = asm;
            this.themeNames = GatherThemeNames();
        }

        #endregion

        #region Property accessors

        public List<string> ThemeNames
        {
            get
            {
                return themeNames;
            }
        }

        #endregion

        #region Methods

        public List<string> GatherThemeNames()
        {
            List<string> ret = new List<string>();
            return ret;
        }
        
        public void ApplyTheme(FrameworkElement frameworkElement, string themeName)
        {
            Uri uri = new Uri(string.Format(@"{0};component/Themes/{1}/Styles.{1}.xaml", asm.FullName.Substring(0, asm.FullName.IndexOf(',')), themeName), UriKind.Relative);
            ImplicitStyleManager.SetResourceDictionaryUri(frameworkElement, uri);
            ImplicitStyleManager.SetApplyMode(frameworkElement, ImplicitStylesApplyMode.Auto);
            ImplicitStyleManager.Apply(frameworkElement);
        }

        #endregion

    }

}